unit wgeteosf;

{****************************************************************************}

interface

uses Wincrt,Windos,
      CartoCmds,        (* Contient les def. globales *)
      tit_win,get_win,gmuf_win,aux_win,coul_win;


(*************************** gethff - 3 Nov 90 *****************************)

function get_eosf(nomsc:string ;var nlig_capt,ncol_capt, nb_band : word;
                  var Title_eos, Band_ID: string;
                  var Ellipso: st47;
                  var pix_size,Long1,Lat1,long2,Lat2,long3,lat3,long4,lat4:real):integer;

{****************************************************************************}

implementation

(*************************** getbmp - 5 Juin 91 *****************************)

function get_eosf(nomsc:string;var nlig_capt,ncol_capt, nb_band : word;
                  var Title_eos, Band_ID: string;
                  var Ellipso: st47;
                  var pix_size,Long1,Lat1,long2,Lat2,long3,lat3,long4,lat4:real):integer;

const

(* FORMAT D'IMAGE IMAGEPRO bmp *)

     card_capt = 8;

var   ier,i,l,k,n:integer;

      eosf:file;
      info_file : text;
      buf_eosf:array[1..1536] of byte;
      txt_eosf:string;
      l_eosf:byte absolute txt_eosf;
      nblock : word;

      val_deg, val_min : integer;

label 999;

begin

  get_eosf := 1;

  ncol_capt := 0;
  nlig_capt := 0;

  {$I-}

  assign(eosf,nomsc);
  reset(eosf,1);
  if ioresult <> 0 then begin get_eosf := -1; goto 999; end;

(* Type eosf *)
  blockread(eosf,buf_eosf,1536);
  close(eosf);

(* WRS *)
  l_eosf := 6;
  for i := 1 to 6 do txt_eosf[i] := char(buf_eosf[20+i]);
  l_eosf := 9;
  for i := 1 to 9 do txt_eosf[i] := char(buf_eosf[26+i]);

  title_eos := copy(txt_eosf,1,length(txt_eosf));
  title_eos := title_eos+' - ';

(* DATE *)
  l_eosf := 19;
  for i := 1 to 19 do txt_eosf[i] := char(buf_eosf[35+i]);
  l_eosf := 8;
  for i := 1 to 8 do txt_eosf[i] := char(buf_eosf[54+i]);

  title_eos := title_eos+copy(txt_eosf,1,length(txt_eosf));
  title_eos := title_eos+' - ';

(* SATELLITE *)
  l_eosf := 12;
  for i := 1 to 12 do txt_eosf[i] := char(buf_eosf[62+i]);
  l_eosf := 2;
  for i := 1 to 2 do txt_eosf[i] := char(buf_eosf[74+i]);

  title_eos := title_eos+copy(txt_eosf,1,length(txt_eosf));
  title_eos := title_eos+' - ';

(* INSTRUMENT *)
  l_eosf := 13;
  for i := 1 to 13 do txt_eosf[i] := char(buf_eosf[76+i]);
  l_eosf := 4;
  for i := 1 to 4 do txt_eosf[i] := char(buf_eosf[89+i]);

  title_eos := title_eos+copy(txt_eosf,1,length(txt_eosf));

(* PIXELS *)
  l_eosf := 17;
  for i := 1 to 17 do txt_eosf[i] := char(buf_eosf[1068+i]);
  l_eosf := 5;
  for i := 1 to 5 do txt_eosf[i] := char(buf_eosf[1085+i]);

  val(txt_eosf,ncol_capt,ier);
  if ier <> 0 then goto 999;

(* LINES *)
  l_eosf := 17;
  for i := 1 to 17 do txt_eosf[i] := char(buf_eosf[1092+i]);
  l_eosf := 5;
  for i := 1 to 5 do txt_eosf[i] := char(buf_eosf[1107+i]);

  val(txt_eosf,nlig_capt,ier);
  if ier <> 0 then goto 999;

(* BANDS *)
  l_eosf := 16;
  for i := 1 to 16 do txt_eosf[i] := char(buf_eosf[1344+i]);
  l_eosf := 7;
  for i := 1 to 7 do txt_eosf[i] := char(buf_eosf[1360+i]);

  Band_Id := copy(txt_eosf,1,length(txt_eosf));
  nb_band := 0;
  for i := 1 to 7 do
    if char(buf_eosf[1360+i]) <> ' ' then nb_band := nb_band + 1;
  if nb_band = 0 then begin
    get_eosf := -2;  goto 999;
  end;

(* RECORD LENGTH *)
  l_eosf := 16;
  for i := 1 to 16 do txt_eosf[i] := char(buf_eosf[1389+i]);
  l_eosf := 5;
  for i := 1 to 5 do txt_eosf[i] := char(buf_eosf[1405+i]);

  val(txt_eosf,nblock,ier);
  if ier <> 0 then goto 999;
  if ncol_capt <> nblock then begin
    get_eosf := -1;  goto 999;
  end;

(* Ellipsoid *)
  l_eosf := 20;
  for i := 1 to 20 do txt_eosf[i] := char(buf_eosf[972+i]);
  Ellipso := copy(txt_eosf,1,20);

(* Pixel size *)
  l_eosf := 5;
  for i := 1 to 5 do txt_eosf[i] := char(buf_eosf[1063+i]);
  val(txt_eosf,pix_size,ier);
  if ier <> 0 then goto 999;

(* Longitudes *)

  l_eosf := 3;
  for i := 1 to 3 do txt_eosf[i] := char(buf_eosf[1116+i]);
  val(txt_eosf,val_deg,ier);
  if ier <> 0 then goto 999;
  l_eosf := 2;
  for i := 4 to 5 do txt_eosf[i-3] := char(buf_eosf[1116+i]);
  val(txt_eosf,val_min,ier);
  if ier <> 0 then goto 999;
  l_eosf := 7;
  for i := 6 to 12 do txt_eosf[i-5] := char(buf_eosf[1116+i]);
  val(txt_eosf,long1,ier);
  if ier <> 0 then goto 999;
  long1 := long1 + val_min*60.0 + val_deg*3600.0;
  if (char(buf_eosf[1129]) = 'W')
      or  (char(buf_eosf[1129]) = 'w') then long1 := -long1;

  l_eosf := 3;
  for i := 1 to 3 do txt_eosf[i] := char(buf_eosf[1174+i]);
  val(txt_eosf,val_deg,ier);
  if ier <> 0 then goto 999;
  l_eosf := 2;
  for i := 4 to 5 do txt_eosf[i-3] := char(buf_eosf[1174+i]);
  val(txt_eosf,val_min,ier);
  if ier <> 0 then goto 999;
  l_eosf := 7;
  for i := 6 to 12 do txt_eosf[i-5] := char(buf_eosf[1174+i]);
  val(txt_eosf,long2,ier);
  if ier <> 0 then goto 999;
  long2 := long2 + val_min*60.0 + val_deg*3600.0;
  if (char(buf_eosf[1187]) = 'W')
      or  (char(buf_eosf[1187]) = 'w') then long2 := -long2;

  l_eosf := 3;
  for i := 1 to 3 do txt_eosf[i] := char(buf_eosf[1232+i]);
  val(txt_eosf,val_deg,ier);
  if ier <> 0 then goto 999;
  l_eosf := 2;
  for i := 4 to 5 do txt_eosf[i-3] := char(buf_eosf[1232+i]);
  val(txt_eosf,val_min,ier);
  if ier <> 0 then goto 999;
  l_eosf := 7;
  for i := 6 to 12 do txt_eosf[i-5] := char(buf_eosf[1232+i]);
  val(txt_eosf,long3,ier);
  if ier <> 0 then goto 999;
  long3 := long3 + val_min*60.0 + val_deg*3600.0;
  if (char(buf_eosf[1245]) = 'W')
      or  (char(buf_eosf[1245]) = 'w') then long3 := -long3;

  l_eosf := 3;
  for i := 1 to 3 do txt_eosf[i] := char(buf_eosf[1290+i]);
  val(txt_eosf,val_deg,ier);
  if ier <> 0 then goto 999;
  l_eosf := 2;
  for i := 4 to 5 do txt_eosf[i-3] := char(buf_eosf[1290+i]);
  val(txt_eosf,val_min,ier);
  if ier <> 0 then goto 999;
  l_eosf := 7;
  for i := 6 to 12 do txt_eosf[i-5] := char(buf_eosf[1290+i]);
  val(txt_eosf,long4,ier);
  if ier <> 0 then goto 999;
  long4 := long4 + val_min*60.0 + val_deg*3600.0;
  if (char(buf_eosf[1303]) = 'W')
      or  (char(buf_eosf[1303]) = 'w') then long4 := -long4;

(* Latitudes *)

  l_eosf := 2;
  for i := 1 to 2 do txt_eosf[i] := char(buf_eosf[1130+i]);
  val(txt_eosf,val_deg,ier);
  if ier <> 0 then goto 999;
  l_eosf := 2;
  for i := 3 to 4 do txt_eosf[i-2] := char(buf_eosf[1130+i]);
  val(txt_eosf,val_min,ier);
  if ier <> 0 then goto 999;
  l_eosf := 7;
  for i := 5 to 11 do txt_eosf[i-4] := char(buf_eosf[1130+i]);
  val(txt_eosf,lat1,ier);
  if ier <> 0 then goto 999;
  lat1 := lat1 + val_min*60.0 + val_deg*3600.0;
  if (char(buf_eosf[1142]) = 'S')
      or  (char(buf_eosf[1142]) = 's') then lat1 := -lat1;

  l_eosf := 2;
  for i := 1 to 2 do txt_eosf[i] := char(buf_eosf[1188+i]);
  val(txt_eosf,val_deg,ier);
  if ier <> 0 then goto 999;
  l_eosf := 2;
  for i := 3 to 4 do txt_eosf[i-2] := char(buf_eosf[1188+i]);
  val(txt_eosf,val_min,ier);
  if ier <> 0 then goto 999;
  l_eosf := 7;
  for i := 5 to 11 do txt_eosf[i-4] := char(buf_eosf[1188+i]);
  val(txt_eosf,lat2,ier);
  if ier <> 0 then goto 999;
  lat2 := lat2 + val_min*60.0 + val_deg*3600.0;
  if (char(buf_eosf[1200]) = 'S')
      or  (char(buf_eosf[1200]) = 's') then lat2 := -lat2;

  l_eosf := 2;
  for i := 1 to 2 do txt_eosf[i] := char(buf_eosf[1246+i]);
  val(txt_eosf,val_deg,ier);
  if ier <> 0 then goto 999;
  l_eosf := 2;
  for i := 3 to 4 do txt_eosf[i-2] := char(buf_eosf[1246+i]);
  val(txt_eosf,val_min,ier);
  if ier <> 0 then goto 999;
  l_eosf := 7;
  for i := 5 to 11 do txt_eosf[i-4] := char(buf_eosf[1246+i]);
  val(txt_eosf,lat3,ier);
  if ier <> 0 then goto 999;
  lat3 := lat3 + val_min*60.0 + val_deg*3600.0;
  if (char(buf_eosf[1258]) = 'S')
      or  (char(buf_eosf[1258]) = 's') then lat3 := -lat3;

  l_eosf := 2;
  for i := 1 to 2 do txt_eosf[i] := char(buf_eosf[1304+i]);
  val(txt_eosf,val_deg,ier);
  if ier <> 0 then goto 999;
  l_eosf := 2;
  for i := 3 to 4 do txt_eosf[i-2] := char(buf_eosf[1304+i]);
  val(txt_eosf,val_min,ier);
  if ier <> 0 then goto 999;
  l_eosf := 7;
  for i := 5 to 11 do txt_eosf[i-4] := char(buf_eosf[1304+i]);
  val(txt_eosf,lat4,ier);
  if ier <> 0 then goto 999;
  lat4 := lat4 + val_min*60.0 + val_deg*3600.0;
  if (char(buf_eosf[1316]) = 'S')
      or  (char(buf_eosf[1316]) = 's') then lat4 := -lat4;

  assign(Info_file,Exepath+'info.tvu');
  rewrite(info_file);
  if ioresult <> 0 then begin get_eosf := -11; goto 999; end;

  Writeln(info_file,'**** EOSAT Fast Format Image ****');
  writeln(info_file);
  l_eosf := 20; (* PRODUCT 9+11 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[1+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 15; (* WRS 6+9 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[21+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 27; (* ACQ. DATE 19+8 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[36+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 14; (* SATELLITE 12+2 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[63+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 17; (* INSTRUMENT 13+4 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[77+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 29; (* PRODUCT TYPE 15+14 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[94+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 25; (* PRODUCT SIZE 15+10 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[123+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 40; (* GEODETIC Processing 30+10 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[226+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 15; (* Resampling 13+2 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[266+i-1]); writeln(info_file,'  '+txt_eosf);

  l_eosf := 19; (* START LINE 14+5 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[442+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 20; (* LINES PER VOL 15+5 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[461+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 20; (* ORIENTATION 14+6 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[481+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 17; (* PROJECTION 13+4 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[501+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 26; (* USGS PROJ. 20+6 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[518+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 22; (* USGS MAP 16+6 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[544+i-1]); writeln(info_file,'  '+txt_eosf);

  l_eosf := 38; (* ELLIPSOID 18+20 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[955+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 29; (* SEM. MAJ. AXIS 18+11 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[993+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 29; (* SEM. MIN. AXIS 18+11 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[1022+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 18; (* PIXEL SIZE 13+5 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[1051+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 22; (* PIX per line 17+5 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[1069+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 22; (* LINE per image 17+5 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[1091+i-1]); writeln(info_file,'  '+txt_eosf);

  l_eosf := 18; (* SUN Elevation 16+2 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[1411+i-1]); writeln(info_file,'  '+txt_eosf);
  l_eosf := 17; (* SUN Azimuth 14+3 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[1429+i-1]); writeln(info_file,'  '+txt_eosf);
  writeln(info_file,'  SCENE CENTER ');
  l_eosf := 13; (* Longitude 13 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[1454+i-1]);
  writeln(info_file,'               LONGITUDE = '+txt_eosf);
  l_eosf := 12; (* Latitude 12 *)
  for i := 1 to l_eosf do txt_eosf[i] := char(buf_eosf[1468+i-1]);
  writeln(info_file,'               LATITUDE  = '+txt_eosf);

  Close(info_file);
{$I+}

  get_eosf := 0;

999:end;

end.

